# Maintainer: Lubosz Sarnecki <lubosz@gmail.com>

_realname=gst-python
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-gst-python" "${MINGW_PACKAGE_PREFIX}-gst-python2")
pkgver=1.16.1
pkgrel=2
pkgdesc="GStreamer GObject Introspection overrides for Python 3 (mingw-w64)"
arch=('any')
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gstreamer"
             "${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-pygobject-devel"
             "${MINGW_PACKAGE_PREFIX}-python2-gobject"
             "${MINGW_PACKAGE_PREFIX}-python3-gobject"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
url='https://gstreamer.freedesktop.org/modules/gst-python.html'
source=(https://gstreamer.freedesktop.org/src/gst-python/${_realname}-${pkgver}.tar.xz)
sha256sums=('b469c8955126f41b8ce0bf689b7029f182cd305f422b3a8df35b780bd8347489')

prepare() {
  cd ${_realname}-${pkgver}

}

build() {
  rm -rf python{2,3}-build
  mkdir python{2,3}-build

  for builddir in python{2,3}-build; do
    pushd ${builddir} > /dev/null

    ${MINGW_PREFIX}/bin/meson \
      --buildtype plain \
      --wrap-mode=nofallback \
      -Dauto_features=enabled \
      -Dpython=${MINGW_PREFIX}/bin/${builddir%-build} \
      ../${_realname}-${pkgver}

      ninja
    popd > /dev/null
  done
}

package_gst-python() {
  pkgdesc="GStreamer GObject Introspection overrides for Python 3 (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-gstreamer"
           "${MINGW_PACKAGE_PREFIX}-python3-gobject")

  cd python3-build

  DESTDIR="${pkgdir}${MINGW_PREFIX}" ninja install

  # The python plugin loader makes problems because it links against libpython
  # which might be in conflict one already used loading the plugin.
  # The overrides don't need it so just remove it for now.
  # https://github.com/Alexpux/MINGW-packages/issues/2034
  rm -r "${pkgdir}${MINGW_PREFIX}/lib/gstreamer-1.0"
}

package_gst-python2() {
  pkgdesc="GStreamer GObject Introspection overrides for Python 2 (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-gstreamer"
           "${MINGW_PACKAGE_PREFIX}-python2-gobject")

  cd python2-build

  DESTDIR="${pkgdir}${MINGW_PREFIX}" ninja install

  # See other package()
  rm -r "${pkgdir}${MINGW_PREFIX}/lib/gstreamer-1.0"
}

package_mingw-w64-i686-gst-python2() {
  package_gst-python2
}

package_mingw-w64-i686-gst-python() {
  package_gst-python
}

package_mingw-w64-x86_64-gst-python2() {
  package_gst-python2
}

package_mingw-w64-x86_64-gst-python() {
  package_gst-python
}
